class Solution {
    public int numPairsDivisibleBy60(int[] time) {
        int mod = 60;
        int ans = 0;
        int tmp;
        Map<Integer, Integer> cnt = new HashMap<>();
        for (int i = 0; i < time.length; i++) {
            tmp = time[i] % mod;
            ans += cnt.getOrDefault((mod - tmp)%mod, 0);
            cnt.put(tmp, cnt.getOrDefault(tmp, 0) + 1);
        }
        return ans;
    }
}